var monthStatisticChart = ring.create({
    
    chart: null,
    boxId: null,
    //[[6000,'Przychod'], [3000,'Oszczednosci']]
    series: [],
    keyMapper: {
        "totalAmountLeft": "Pozostało",
        "totalSaved": "Oszczędności",
        "totalExpenses": "Wydatki",
        "saldo": "Saldo",
        "totalIncome": "Przychód",
        "amountLeft": "Poporzedni miesiąc"
    },
    
    constructor: function(boxId, series)
    {
        this.boxId  = boxId;
        this.series = series;
    },
    
    formatToArr: function(series)
    {
        var arr = [], label;
        
        for (var key in this.keyMapper) {
            label = this.keyMapper[key];
            arr.push([parseFloat(series[key]), label]);
        }
        
        return arr;
    },
    
    showChart: function() 
    {
        var series = this.formatToArr(this.series);
        
        this.chart = $.jqplot(this.boxId, [
            series
            ], {
                //35D442
                seriesColors: [
                    '#9BEEF2', //light blue Pozostało
                    '#35D442', //green //Oszczędności
                    '#F23838', //red //Wydatki
                    '#17BDB8', //blue //Saldo
                    '#DDFC2D', //brown //Przychód
                    '#FAA2EA' //blue Poporzedni miesiąc
                ],
            seriesDefaults: {
                renderer:$.jqplot.BarRenderer,
                // Show point labels to the right ('e'ast) of each bar.
                // edgeTolerance of -15 allows labels flow outside the grid
                // up to 15 pixels.  If they flow out more than that, they
                // will be hidden.
                pointLabels: { show: true, location: 'e', edgeTolerance: -15 },
                // Rotate the bar shadow as if bar is lit from top right.
                shadowAngle: 135,
                // Here's where we tell the chart it is oriented horizontally.
                rendererOptions: {
                    barDirection: 'horizontal',
                    varyBarColor: true
                }
            },
            axes: {
                yaxis: {
                    renderer: $.jqplot.CategoryAxisRenderer,
                    tickOptions: {
                        //formatString: '%.2f'
                      } 
                },
                xaxis: {
                    tickOptions: {
                        formatString: '%.2f'
                      } 
                }
            }
        });
    },
    
    replot: function(series)
    {
        var formatedSeries = this.formatToArr(series);
        
        this.chart.replot({data:[formatedSeries]});
    }
});


